<template>
  <div class="app-container">
    <div class="app-main">
      <div class="mainName">
        项目列表
        <span class="spanRight" style="margin: 0 8px"
          >今日新增有蚁
          <span class="red">{{ todayAdd || 0 }}</span>
        </span>
        <span class="spanRight" style="margin-right: 8px"
          >有蚁总数
          <span class="blue">{{ termiteTotal || 0 }}</span>
        </span>
        <span class="spanRight" style="margin-right: 8px"
          >处理中
          <span class="yellow">{{ handleTotal || 0 }}</span>
        </span>
        <span class="spanRight"
          >待上传结果
          <span class="green">{{ uploadTotal || 0 }}</span>
        </span>
      </div>
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="状态" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="请选择"
            filterable
            clearable
          >
            <el-option
              v-for="users in statusList"
              :key="users.value"
              :label="users.label"
              :value="users.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="项目名称" prop="projectName">
          <el-input
            v-model="queryParams.projectName"
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="点位号" prop="id">
          <el-input
            v-model="queryParams.id"
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="报警时间">
          <el-date-picker
            v-model="alarmDate"
            format="yyyy-MM-dd"
            @change="changeAlarmDate"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item style="float: right">
          <el-button type="primary" size="mini" @click="handleQuery"
            >查询</el-button
          >
          <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >-->
        </el-form-item>
      </el-form>

      <el-table
        v-loading="loading"
        :data="assetList"
        border
        stripe
        @selection-change="handleSelectionChange"
        :key="1"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="序号"
          align="center"
          type="index"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column label="点位号" align="center" prop="id" />
        <el-table-column
          label="所属项目"
          align="center"
          prop="projectName"
          min-width="200"
        />
        <el-table-column
          label="所属白蚁防治公司"
          align="center"
          prop="controlName"
          min-width="200"
        />
        <el-table-column
          label="小区物业公司"
          align="center"
          prop="propertyManagementCompany"
          min-width="200"
        />
        <el-table-column
          label="小区性质"
          align="center"
          prop="projectType"
          min-width="200"
        />
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <span v-if="scope.row.status === '1'">无蚁</span>
            <span v-else-if="scope.row.status === '2'">有白蚁</span>
            <span v-else-if="scope.row.status === '3'">灭杀中</span>
            <span v-else-if="scope.row.status === '6'">已灭杀</span>
            <span v-else>{{ scope.row.status }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="报警时间"
          align="center"
          prop="alarmTime"
          min-width="220"
        />
        <el-table-column
          label="更新时间"
          align="center"
          prop="updateTime"
          min-width="220"
        />

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="230"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="dispose(scope.row)"
              >处理</el-button
            >
            <el-button size="mini" type="text" @click="seeLog(scope.row)"
              >日志</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        class="pagination-container"
      />
    </div>
    <dispose
      v-if="disposeShow"
      :submitForm="submitForm"
      :show="disposeShow"
      @closeMsg="closeDispose"
    ></dispose>
    <log v-if="logShow" :id="id" :show="logShow" @closeMsg="closeLog"></log>
  </div>
</template>

<script>
import {
  queryMonitorPointTermite, // 项目列表-有蚁
  termiteCountDataQuery, // 有蚁列表中的顶部数据
} from "@/api/manage/asset";
import { getPersonnelList } from "@/api/manage/personnel";
import { getDepartmentList } from "@/api/manage/department";
import { getUserlist } from "@/api/system/user";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import dispose from "./components/dispose";
import log from "./components/log";

export default {
  name: "antList",
  dicts: [],
  components: { dispose, log },
  data() {
    return {
      logShow: false,
      disposeShow: false,
      alarmDate: [],

      imgUrl: "",
      id: null,
      submitForm: {
        id: "",
        monitorName: "",
        projectName: "",
        controlName: "",
        controlId: "",
        relay: "",
        rssi: "",
        snr: "",
        voltage: "",
        photoTermite: "",
        photoControl: "",
        detailSituation: "",
        reasonAlarm: "",
      },
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      messageTotal: 0,
      // 资产信息表格数据
      assetList: [],
      messageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 资产分类树桩选项
      assetClassificationOptions: [],
      // 启用日期时间范围
      daterangeStartDate: [],
      // 部门树桩选项
      deptOptions: [],
      // 归属账号下拉选项
      statusList: [
        {
          value: "有蚁",
          label: "有蚁",
        },
        {
          value: "灭治中",
          label: "灭治中",
        },
        {
          value: "已灭治",
          label: "已灭治",
        },
      ],
      specificList: [
        {
          value: "是",
          label: "是",
        },
        {
          value: "否",
          label: "否",
        },
      ],
      reasonList: [
        {
          value: "木材腐烂",
          label: "木材腐烂",
        },
        {
          value: "人为破坏",
          label: "人为破坏",
        },
        {
          value: "设备调试",
          label: "设备调试",
        },
        {
          value: "模块更换",
          label: "模块更换",
        },
        {
          value: "其他昆虫",
          label: "其他昆虫",
        },
      ],
      // 是否显示二维码弹出层
      getCodeUrlOpen: false,
      // 打印弹出层
      openPrint: false,
      assets: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        alarmTimeStart: "",
        alarmTimeEnd: "",
        // status: "",
        // projectName: "",
        // id: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 导入结果弹出框
      resultVisible: false,
      // 人员下拉
      personnels: [],
      // 部门下拉
      departments: [],
      handleTotal: 0,
      termiteTotal: 0,
      uploadTotal: 0,
      todayAdd: 0,
    };
  },
  created() {
    this.getList();
    this.init();
  },
  methods: {
    init() {
      termiteCountDataQuery().then((res) => {
        console.log(res, "00000");
        if (res.errorCode === "000000") {
          this.handleTotal = res.data.handleTotal;
          this.termiteTotal = res.data.termiteTotal;
          this.uploadTotal = res.data.uploadTotal;
          this.todayAdd = res.data.todayAdd;
        }
      });
    },
    closeDispose(val) {
      if (val) {
        this.getList();
      }
      this.disposeShow = false;
    },
    closeLog(val) {
      if (val) {
        this.getList();
      }
      this.logShow = false;
    },
    changeAlarmDate(val) {
      console.log(val, "bbb");
      if (val) {
        this.queryParams.alarmTimeStart = val[0];
        this.queryParams.alarmTimeEnd = val[1];
      } else {
        this.queryParams.alarmTimeStart = "";
        this.queryParams.alarmTimeEnd = "";
      }
    },

    refresh() {},
    handleSelectionChange(val) {
      console.log(val, "00000");
    },
    indexMethod(index) {
      return index + 1;
    },
    dispose(row) {
      // 在这里调接口获取详情
      this.disposeShow = true;
      this.submitForm = row;
    },
    seeLog(row) {
      console.log(row);
      this.logShow = true;
      this.id = row.id;
    },
    message(row) {},
    deleteItem(row) {
      console.log(row);
    },
    messageEdit(row) {
      this.imgUrl = row.voucher;
      this.voucherVisible = true;
    },
    // messageDel(row) {},
    /*人员下拉选项*/
    getDepartment() {
      getDepartmentList().then((response) => {
        this.departments = response.rows;
      });
    },
    /*人员下拉选项*/
    getPersonnel() {
      getPersonnelList().then((response) => {
        this.personnels = response.rows;
      });
    },

    /** 二维码按钮操作 */
    getCodeUrl(row) {
      this.reset();
      this.getCodeUrlOpen = true;
      this.title = "rfid编码（" + row.rfidCode + ")";
      // 生成二维码
      this.$nextTick(function () {
        console.log(document.getElementById("qrCodeUrl"));
        document.getElementById("qrCodeUrl").innerHTML = "";
        let qrCodeUrl = new QRCode("qrCodeUrl", {
          width: 200,
          height: 200,
          text: row.rfidCode,
          colorDark: "#000000",
          colorLight: "#fff",
        });
      });
    },
    /*归属账号下拉选项*/
    getUser() {
      getUserlist().then((response) => {
        this.statusList = response.rows;
      });
    },
    /*部门树桩选项*/
    getTreeselect() {
      treeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    getMessageList() {
      console.log("获取短信列表");
    },
    /** 查询资产信息列表 */
    getList() {
      this.loading = true;
      queryMonitorPointTermite(this.queryParams)
        .then((res) => {
          console.log(res, "23232");
          if (res.errorCode == "000000") {
            this.assetList = res.data.list;
            this.total = res.data.total;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        assetName: null,
        assetCode: null,
      };
      this.resetForm("form");
      this.openPrint = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.reset();
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // addItem() {
    //   console.log("新增");
    //   this.bindCompanyShow = 2;
    // },
    /** 重置按钮操作 */
    // resetQuery() {
    //   this.reset();
    //   this.resetForm("queryForm");
    //   this.handleQuery();
    // },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除资产信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delAsset(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.app-main {
  background-color: #fff;
  // padding: 15px 20px;
  border-radius: 8px;
  .btnGroupLeft {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
  }
  .spanRight {
    font-size: 12px;
    color: #303133;
    .red {
      color: red;
    }
    .blue {
      color: blue;
    }
    .yellow {
      color: #ffc14b;
    }
    .green {
      color: green;
    }
  }
  .formBox {
    .left {
      display: inline-block;
      height: 44px;
      line-height: 44px;
      width: 100px;
      padding-right: 15px;
      border-left: 1px solid #e4e4dc;
      border-right: 1px solid #e4e4dc;
      font-family: MicrosoftYaHei;
      font-size: 12px;
      color: #303133;
      text-align: right;
      vertical-align: top;
    }
    .right {
      display: inline-block;
      width: calc(100% - 100px);
      height: 44px;
      line-height: 32px;
      font-family:
        PingFangSC,
        PingFang SC;
      font-weight: 400;
      font-size: 12px;
      color: #303133;
      border-right: 1px solid #e4e4dc;
      padding: 6px 15px;
      .el-select {
        width: 340px !important;
      }
      .el-input {
        width: 340px !important;
      }
    }
    .formHead {
      width: 100%;
      height: 44px;
      background-color: #5d6d7f;
      height: 44px;
      line-height: 44px;
      text-align: center;
      font-family: MicrosoftYaHei, MicrosoftYaHei;
      font-weight: bold;
      font-size: 12px;
      color: #ffffff;
    }
    .formWhite {
      width: 100%;
      height: 44px;
      background-color: #fff;
      border-bottom: 1px solid #dcdfe6;
    }
    .area {
      .areaLeft {
        width: 130px !important;
        margin-right: 10px;
      }
      .areaRight {
        width: 200px !important;
      }
    }
    .formGray {
      width: 100%;
      height: 44px;
      background-color: #dbe2e6;
    }
  }
  .mainName {
    font-family:
      PingFangSC,
      PingFang SC;
    font-weight: 500;
    font-size: 16px;
    height: 30px;
    line-height: 30px;
    color: #000000;
    border-bottom: 1px solid #dcdfe6;
    margin-bottom: 10px;
  }
  .headerTable {
    background: #5d6d7f;
    height: 48px;
    line-height: 48px;
    text-align: center;
    width: 100%;
    color: #fff;
    font-weight: Bold;
    font-size: 14px;
    font-family:
      Helvetica Neue,
      Helvetica,
      PingFang SC,
      Hiragino Sans GB,
      Microsoft YaHei,
      Arial,
      sans-serif;
    border: 1px solid #e3e3e3;
    border-bottom: 0;
  }
}
.el-collapse .el-collapse-item__header {
  font-size: 16px;
  font-weight: bold;
}

.pagination-container {
  margin-top: 20px;
  width: 100%;
}

.pagination-container .el-pagination {
  display: flex;
  justify-content: center;
  width: 100%;
}
::v-deep .el-date-editor {
  width: 300px;
}
</style>
